package com.apac.dao;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;

import com.apac.bom.AbstractBOM;

public abstract class AbstractDAO {

	protected EntityManagerFactory factory = Persistence.createEntityManagerFactory("APACSalesTrackingSystem");
	protected EntityManager em = factory.createEntityManager();
	protected EntityTransaction tx = em.getTransaction();
	
	public abstract AbstractBOM findByKey(String id);
	
	public abstract List<AbstractBOM> findAll();
	
	public boolean insert(AbstractBOM entity) {
		// TODO Auto-generated method stub
		try {
			tx.begin();
			em.persist(entity);
			em.flush();
			em.clear();
			tx.commit();
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			tx.rollback();
		}finally{
			em.close();
		}
		return false;
	}
	
	public abstract boolean update(AbstractBOM entity);
	
	public abstract boolean delete(AbstractBOM entity);
}
